package unclassified.simple;

public class LCOF_53 {

    public int search(int[] nums, int target) {
        int res = 0;
        for (int num : nums) {
            if(num == target) {
                res++;
            }
        }
        return res;
    }

    public int midSearch(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if(nums[mid] < target) {
                l = mid + 1;
            } else if (nums[mid] > target) {
                r = mid - 1;
            } else {
                if (nums[r] != target) {
                    r--;
                } else if(nums[l] != target) {
                    l++;
                } else {
                    break;
                }
            }
        }
        return r - l + 1;
    }
}
